clear all
set more off

cd "C:\Dropbox\Average_target_survey\replication_folder\workfiles"
use step001, clear

***collapse days when the sample size is small
gen start_day2=start_day1
recode start_day2 30/32=29

*** Have you heard any news about the Fed
gen QJH3_Yes=(QJH3==2) if QJH3~=. 
* tab start_day1 QJH3 [aw=weight], row nofreq

*** How many pieces of news about the Fed did you heard
tab start_day1 QJH4  [aw=weight] , row nofreq  
forvalues i=1(1)5 {
	gen QJH4_`i'=(QJH4==`i') if QJH4~=.
}
*** Where did you hear the news
 tabstat QJH5_1 QJH5_2 QJH5_3 QJH5_4 QJH5_5 QJH5_6 QJH5_7 QJH5_8 QJH5_9 [aw=weight], by(start_day1) format("%3.2f")

*** When did you hear the news
forvalues i=0(1)6 {
	gen QJH6_`i'=(QJH6==`i') if QJH6~=.
}

*** What did you hear about the Fed
tabstat QJH7_1 QJH7_2 QJH7_3 QJH7_4 QJH7_5 QJH7_6 [aw=weight], by(start_day1) format("%3.2f")

*** Who did you hear about the Fed
tabstat QJH8_1 QJH8_2 QJH8_3 QJH8_4 QJH8_5 QJH8_6 [aw=weight], by(start_day1) format("%3.2f")

*** What is the Fed doing (objective)
tabstat QJH9_1 QJH9_2 QJH9_3 QJH9_4 QJH9_5 QJH9_6 QJH9_7 QJH9_8 QJH9_9 [aw=weight], by(start_day1) format("%3.2f")

*** What does Fed in terms of prices?
tabstat QJH10_1 QJH10_2 QJH10_3 QJH10_4 QJH10_5 QJH10_6 QJH10_7 [aw=weight], by(start_day1) format("%3.2f")

tempname 1
postfile `1'  str50 variable ///
	str50 E_statistic ///
	str12 E_aug26 ///
	str12 E_aug27AM ///
	str12 E_aug27PM ///
	str12 E_aug28 ///
	str12 E_aug29 ///
	using "C:\Dropbox\Average_target_survey\replication_folder\outregs\Tables_01_02.dta", replace every(1)
	
*** create dummy variables for each day	
foreach var in 26 28 29 {	
	gen aug`var'=(start_day2==`var')
	gen _aug`var'=aug`var'*sqrt(weight)
}	

gen aug27A=(start_day2==27 & start_hour<12)
gen aug27B=(start_day2==27 & start_hour==12)
gen _aug27A=aug27A*sqrt(weight)
gen _aug27B=aug27B*sqrt(weight)


	
foreach var in ///
	QJH3_Yes /// Have you heard any news about the Fed
	 QJH4_2 QJH4_3 QJH4_4 QJH4_5 QJH4_1 /// How many pieces of news about the Fed did you heard
	QJH5_1 QJH5_2 QJH5_3 QJH5_4 QJH5_5 QJH5_6 QJH5_7 QJH5_8 QJH5_9  /// Where did you hear the news
	QJH6_0 QJH6_1 QJH6_2 QJH6_3 QJH6_4 QJH6_5 QJH6_6 /// When did you hear the news
	QJH7_1 QJH7_2 QJH7_3 QJH7_4 QJH7_5 QJH7_6  ///  What did you hear about the Fed
	QJH8_1 QJH8_2 QJH8_3 QJH8_4 QJH8_5 QJH8_6 /// Who did you hear about the Fed
	QJH9_1 QJH9_2 QJH9_3 QJH9_4 QJH9_5 QJH9_6 QJH9_7 QJH9_8 QJH9_9 ///  What is the Fed doing (objective)
	QJH10_1 QJH10_2 QJH10_3 QJH10_4 QJH10_5 QJH10_6 QJH10_7 QJH10_A /// What does Fed in terms of prices?
				{
		
			    
	
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			*** raw mean
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			reg `var' aug26 aug27A aug27B aug28 aug29 [aw=weight], robust nocons
			test aug26 = aug27A
			local p1A=r(p)
			test aug26 = aug27B
			local p1B=r(p)			
			test aug26 = aug28
			local p2=r(p)
			test aug26 = aug29
			local p3=r(p)			
			
			local M26_mean=string(_b[aug26],"%4.2f")
			local M27A_mean=string(_b[aug27A],"%4.2f")
			local M27B_mean=string(_b[aug27B],"%4.2f")
			local M28_mean=string(_b[aug28],"%4.2f")
			local M29_mean=string(_b[aug29],"%4.2f")

			if abs(`p1A')<0.1 & `p1A'~=. local M27A_mean="`M27A_mean'" + "*"
			if abs(`p1B')<0.1 & `p1B'~=. local M27B_mean="`M27B_mean'" + "*"			
			if abs(`p2')<0.1 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.1 & `p3'~=. local M29_mean="`M29_mean'" + "*"
			
			if abs(`p1A')<0.05 & `p1A'~=. local M27A_mean="`M27A_mean'" + "*"
			if abs(`p1B')<0.05 & `p1B'~=. local M27B_mean="`M27B_mean'" + "*"
			if abs(`p2')<0.05 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.05 & `p3'~=. local M29_mean="`M29_mean'" + "*"
			
			if abs(`p1A')<0.01 & `p1A'~=. local M27A_mean="`M27A_mean'" + "*"
			if abs(`p1B')<0.01 & `p1B'~=. local M27B_mean="`M27B_mean'" + "*"
			if abs(`p2')<0.01 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.01 & `p3'~=. local M29_mean="`M29_mean'" + "*"				
			
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			*** post results
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			post `1' ("`var'") ("raw mean")	("`M26_mean'") ("`M27A_mean'") ("`M27B_mean'") ("`M28_mean'")  ("`M29_mean'")  

}

postclose `1'
